﻿using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;

namespace cad
{
    // 这个类是调用 PickAndStretch 的地方
    public class StretchCommand
    {
        [CommandMethod("aaa")]
        public void StartStretchOperation()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            try
            {
                // 提示用户选择图框区域
                PromptSelectionResult selectionResult = ed.GetSelection();

                // 检查是否选择了对象
                if (selectionResult.Status != PromptStatus.OK)
                {
                    ed.WriteMessage("没有选择任何对象。\n");
                    return;
                }

                // 选择有效图框后，调用 PickAndStretch 来处理
                PickAndStretch stretchCommand = new PickAndStretch();
                stretchCommand.pickAndstretch(selectionResult);
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage($"\n发生异常：{ex.Message}");
            }
        }
    }
}
